
var HorseSprite = cc.Sprite.extend({
        disappearAction : null,
    move_time : 0.5, 
    radiu : 100,
    is_running : 0,
    index : 0,
	frames :  null,
    onEnter : function() {
            this._super(); 

            this.disappearAction = this.createDisappearAction();
            this.disappearAction.retain(); 
			frames = [];
    },

    onExit : function() {
            this.disappearAction.release();
            this._super();
    },
    runDisappear : function(target) { 
            console.log("runDisappear...");
            target.setZOrder(100);

            target.stopAllActions();
            //定义消失动画
            var ac = target.disappearAction;
            var seqAc = cc.Sequence.create(ac, cc.CallFunc.create(function() {
                    console.log("callfun....");

                    target.removeFromParent(); 
            }, target));

            target.runAction(seqAc);
    },

    go : function() {
            //开始逃离
            //随机一个角度
            var angle = cc.random0To1() * 2 * Math.PI;

            //计算目标点
            var tp = cc.p(this.x + this.radiu * Math.cos(angle), this.y + this.radiu * Math.sin(angle)); 
			
            //下面开始逃离
            var mv = new cc.MoveTo(this.move_time, tp);
		
			//创建动画	
			this.frames = [];
			cc.spriteFrameCache.addSpriteFrames(res.horse_plist);
			var frames = [];
			for (var i = 0; i < 4; i++) {
					var str = "h" + (4-i) + ".png";
					var frame = cc.spriteFrameCache.getSpriteFrame(str);
					this.frames.push(frame);
			} 
			var animation = new cc.Animation(this.frames, 0.05);
			var action_run = new cc.Animate(animation);			

            var seq_ac = cc.Sequence.create(mv, cc.CallFunc.create(function(sender) {
                    sender.is_running = 0;
                    sender.getParent().addOverCount(sender);
            },this));

			this.runAction(new cc.repeatForever(action_run));
            this.runAction(seq_ac); 
            this.is_running = 1;
    },

    createDisappearAction : function() { 
            var size = cc.winSize;
            var x = cc.random0To1() * size.width;
            var action = cc.MoveTo.create(0.1, cc.p(x, size.height + 30));
            return action;
    },

    removeTouchEventListenser : function(){
            cc.eventManager.removeListener(this.touchListener);
    },

});



